package com.faiz.algorithm;

public class ListNode {
    public int val;
    public ListNode next;

    public ListNode(int x) {
        val = x;
    }

    ListNode() {
    }

    public static class Builder {
        private final ListNode head;

        public Builder() {
            head = new ListNode(-1);
        }

        public ListNode build() {
            return head;
        }

        public Builder(int... nums) {
            head = buildLinkedList(0, nums);
        }

        private ListNode buildLinkedList(int i, int[] nums) {
            if (i >= nums.length) return null;
            ListNode node = new ListNode(nums[i]);
            node.next = buildLinkedList(i + 1, nums);
            return node;
        }

        public Builder(int val) {
            head = new ListNode(val);
        }
    }
}
